package pruebas;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class JuegosDAO {

	
	   public void insertJuego(){
	    	
		    //	
		    	Connection conn = null;
		    	Statement stmt = null;
		    	ResultSet rs = null;

		    	try {
		    		Class.forName("com.mysql.jdbc.Driver").newInstance();
		    		
		    		//conn = DriverManager.getConnection( "jdbc:mysql://localhost/jbdb", "", "123456" );
		    		
		    		conn = 
		    		       DriverManager.getConnection("jdbc:mysql://localhost/jbdb?" + 
		    		                                   "user=root&password=123456");

		    	    stmt = conn.createStatement();
		    	    rs = stmt.executeQuery("SELECT * FROM juegos");

		    	    // or alternatively, if you don't know ahead of time that
		    	    // the query will be a SELECT...

		    	    if (stmt.execute("SELECT * FROM juegos")) {
		    	        rs = stmt.getResultSet();
		    	        
		    				
		    			}

		    	        while (rs.next()) {
		    	        	
		    	        	Juego unjuego = new Juego();
		    	        	unjuego.setNombre(rs.getString("nombre"));
		    	        	
		    	        	 //System.out.println(rs.getString("nombre"));
		    			}
		    	        
		    	       
		    	    
		    	    // Do something with the Connection
		    	}
		    	catch (SQLException ex){
		    	    // handle any errors
		    	    System.out.println("SQLException: " + ex.getMessage());
		    	    System.out.println("SQLState: " + ex.getSQLState());
		    	    System.out.println("VendorError: " + ex.getErrorCode());
		    	} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		    	finally {
		    	    // it is a good idea to release
		    	    // resources in a finally{} block
		    	    // in reverse-order of their creation
		    	    // if they are no-longer needed

		    	    if (rs != null) {
		    	        try {
		    	            rs.close();
		    	        } catch (SQLException sqlEx) { } // ignore 

		    	        rs = null;
		    	    }

		    	    if (stmt != null) {
		    	        try {
		    	            stmt.close();
		    	        } catch (SQLException sqlEx) { } // ignore

		    	        stmt = null;
		    	    }
		    	}
		    }
}
